<template>
  <div>
    <el-table :data="roleData" border style="width: 100%">
      <el-table-column prop="role_id" label="角色KEY" width="1100">
      </el-table-column>
      <el-table-column align="center" prop="name" label="角色名称" width="200">
      </el-table-column>
      <el-table-column align="center" prop="desc" label="角色描述" width="200">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click="lookRolePermission(scope.row.id)"
            >查看权限</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="查看权限" :visible.sync="dialogVisible" width="50%">
      <p style="margin: 40px 80px">
        <strong style="margin-right: 20px">角色名称:</strong> {{ roleName }}
      </p>
      <p style="margin: 40px 80px">
        <strong>菜单:</strong>
        <el-tree style="margin-left: 50px;" :data="menus" :props="defaultProps1"></el-tree>
      </p>
      <p style="margin: 40px 80px">
        <strong>权限:</strong>
        <el-tree style="margin-left: 50px;" :data="accesses" :props="defaultProps2"></el-tree>
      </p>
    </el-dialog>
  </div>
</template>

<script>
import { getRoleList, lookRolePermission } from "../../api/role";
export default {
  data() {
    return {
      roleData: [],
      page: 1,
      limit: 20,
      total: 0,
      dialogVisible: false,
      roleName: "",
      accesses: [],
      menus: [],
      defaultProps1: {
        children: "children",
        label: "title",
      },
      defaultProps2: {
        children: "children",
        label: "title",
      },
    };
  },
  mounted() {
    this.getRoleList();
  },
  methods: {
    async getRoleList() {
      let res = await getRoleList(this.page, this.limit);
      console.log(res);
      this.roleData = res.items;
      this.total = res.total;
    },
    async lookRolePermission(id) {
      this.dialogVisible = true;
      let res = await lookRolePermission(id);
      console.log(res);
      this.roleName = res.name;
      this.accesses = res.accesses
      this.menus = res.menus
    },
  },
};
</script>

<style scoped >
</style>
